<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图片压缩</title>
    <script src="require.min.js"></script>
</head>
<body>
<input id="input" multiple type="file" accept="image/*">
<script>
    require(['./bin/compress.js'], function ({default: compress}) {
        document.getElementById('input').addEventListener('change', ({target: {files}}) => {
                console.log(files);
                for (let i = 0; i < files.length; i++) {
                    console.log(files[i]);
                    let image = new Image();
                    image.src = URL.createObjectURL(files[i]);
                    image.addEventListener('load', () => {
                        compress(image, 1024 * 20, 0.3, {debug: true}).then((blob) => {
                            console.log(blob);
                        }).catch(error => {
                            alert(error.toString());
                        });
                    });
                }
            }
        );
        console.log(compress);
    });
</script>
</body>
</html>
